<?php

/**
 * @author      Dennis Greulich / Pionier 
 * 
 * @package AllianzTool3
 * @version $Id: reg.php 3 2010-01-24 09:20:21Z allytools $
 * @copyright (c) 2009 Allytools
 * @license http://creativecommons.org/licenses/by-sa/3.0/de/
 *
 */

//Includes
require ("./config.php");
require ("./system/functions.php");
require ("./system/class/mysql.class.php");
require ("./system/libs/Smarty.class.php");
include './language/'.SYS_LANG.'/register.php';

// Verbindung zur DB aufbauen
$db = new mysql(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
$db->connect();

ob_start();
session_start();

if(isset($_POST['register']))
{

    $db = new mysql(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
    $db->connect();
    
    $username   = strip_tags(str_replace('\'', '"', $_POST['username']));
    $password   = strip_tags(str_replace('\'', '"', $_POST['password']));
    $email      = strip_tags(str_replace('\'', '"', $_POST['email']));
    $hp_ga      = strip_tags(str_replace('\'', '"', $_POST['user_hp_ga']));
    $hp_sys     = strip_tags(str_replace('\'', '"', $_POST['user_hp_sys']));
    $hp_po      = strip_tags(str_replace('\'', '"', $_POST['user_hp_po']));
    $date       = date("d-m-Y H:i:s");
    
    $data['ally_id']    = 0;
    $data['username']   = $username;
    $data['userpass']    = md5("$password");;
    $data['hp_galaxy']  = $hp_ga;
    $data['hp_system']  = $hp_sys;
    $data['hp_planet']  = $hp_po;
    $data['email']      = $email;
    $data['style']      = "default";
    $data['language']   = "de";
    $data['status']     = "email";
    $data['reg_date']  = $date;
    

    if($username == NULL OR $password == NULL OR $email == NULL OR $hp_ga == NULL OR $hp_sys == NULL OR $hp_po == NULL)
    {
        $final_report.= $_l_error_emty;
    }
    else
    {
        if(strlen($username) <= 3 || strlen($username) >= 30)
        {
            $final_report.="Your username must be between 3 and 30 characters..";
        }
        else
        {
            $sql = "SELECT * FROM `".TABLE_USER."` WHERE `username` = '".$username."'";
            $row = $db->query($sql);
            
            if($db->affected_rows != 0)
            {
                $final_report.="The username is already in use!";
            }
            else
            {
                if(strlen($password) < 6)
                {
                    $final_report.="Your password must be between 6 and 12 digits and characters..";
                }
                else
                {
                    if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email))
                    {
                        $final_report.="Your email address was not valid..";
                    }
                    else
                    {
                        $db->query_insert("user", $data);
                        
                        $final_report.="Meldung OK";
                    }
                }
            }
        }
    }
    $db->close();
}

$tpl = new Smarty;

$tpl->assign('title',$l_title);
$tpl->assign('report',$final_report);
$tpl->assign('name',$l_user_name);
$tpl->assign('pass',$l_user_password);
$tpl->assign('pass2',$l_user_password2);
$tpl->assign('user_mail',$l_user_mail);
$tpl->assign('user_hp',$l_user_hp);
$tpl->assign('reg_button_1',$l_move_forward);
$tpl->assign('back',$l_move_back);

$tpl->assign('style', SYS_STYLE); //Style laden
$tpl->assign('lang', SYS_LANG); //Sprache laden
$tpl->debugging = TPL_DEBUG; //Debuggen
$tpl->display('register.html'); //Template ausgeben


?>